package com.sdy.hospitalguard.embed.mq.consumer;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sdy.common.utils.DateUtil;
import com.sdy.hospitalguard.biz.constants.MqConstants;
import com.sdy.hospitalguard.biz.model.MatchingPeople;
import com.sdy.hospitalguard.embed.keepalive.process.DataProcess;
import com.sdy.mq.base.BaseMessageConsumer;
import com.sdy.mvc.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.nio.charset.Charset;
import java.util.Date;

/**
 * <p>
 * 消费
 * </p>
 *
 * @author fb
 * @since 2020/5/8
 */
@Slf4j
@Component
public class ServerConsumer extends BaseMessageConsumer {

    @Autowired
    private DataProcess dataProcess;

    @Override
    protected boolean consume(MessageExt message) {
        String msgBody = new String(message.getBody(), Charset.forName(RemotingHelper.DEFAULT_CHARSET));;
        switch (message.getTags()) {
            case MqConstants.Tags.TAG_EMBED_SERVER:
                /*JSONObject object = new JSONObject(true);
                try {
                    String[] msgBodys = msgBody.split("##hzsdy##");
                    String url = msgBodys[0];
                    String body = msgBodys[1];
                    if ("/LAPI/V1.0/System/Event/Notification/PersonVerification".equals(url)) {
                        object = JSONObject.parseObject(body);
                        dataProcess.analysis(object);
                    }
                }catch (Exception e) {
                    log.error("系统处理识别数据异常：", e);
                    log.error("人员信息：{}", object);
                }*/
                break;
            case MqConstants.Tags.TAG_ACCESS_ADD:
                dataProcess.addPersonProcess(JsonUtil.deserialize(msgBody.getBytes(), MatchingPeople.class));
                break;
            case MqConstants.Tags.TAG_ACCESS_DELETE:
                dataProcess.deletePersonProcess(msgBody);
                break;
            default:
                break;
        }
        return true;
    }

}
